import Koa from 'koa';
import useRouters from './router/index.js';
import cors from '@koa/cors';
import bodyParser from 'koa-bodyparser';

const app = new Koa();

// 配置 CORS
app.use(
  cors({
    origin: '*', // 允许的前端域名
    credentials: true, // 如果需要发送 cookies
    allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
    allowHeaders: ['Content-Type', 'Authorization'],
  })
);
app.use(bodyParser());

useRouters(app);

app.listen(3000, () => {
  console.log('server is running at port 3000');
});
